﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Labb3.View
{
    class Shockwave
    {
        Vector2 _startingPosition;
        Texture2D _shockwaveTexture;
        Camera _camera;
        float _maxDuration = 1f;
        float _currentDuration = 0f;
        float _shockwaveSpeed;
        float _diameter;
        Color _color;

        public Shockwave(Vector2 startingPosition, Texture2D shockwaveTexture, float diameter, Camera camera)
        {
            _camera = camera;
            _startingPosition = startingPosition;
            _shockwaveTexture = shockwaveTexture;
            _diameter = diameter;
            _shockwaveSpeed = 0.001f;
        }

        public void Update(GameTime gameTime)
        {
            _currentDuration += _shockwaveSpeed * (float)gameTime.ElapsedGameTime.Milliseconds;
            float cC = 1f - _currentDuration;
            _color = new Color(cC, cC, cC, cC);
            //_color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
            //System.Diagnostics.Debug.WriteLine(_currentDuration);
        }

        public void Draw(SpriteBatch spriteBatch)
        {           
            Vector2 origin = new Vector2(63f, 63f);
            //Vector2 origin = new Vector2(_camera._offsetX, _camera._offsetY);

            int visualDiameter = (int)(_camera.GetVisualCoords(new Vector2((float)_diameter, (float)_diameter)).X);
            int currentDiameter = (int)(visualDiameter * _currentDuration);
            Vector2 visualPosition = _camera.GetVisualCoords(_startingPosition);
            Rectangle drawRect = new Rectangle((int)visualPosition.X, (int)visualPosition.Y, currentDiameter, currentDiameter);
            spriteBatch.Draw(_shockwaveTexture, drawRect, null, _color, 0f, origin, SpriteEffects.None, 0f);
            //System.Diagnostics.Debug.WriteLine("Draw");
        }
    }
}
